/*
 * TimeoutHandler.cpp
 *
 *  Created on: Dec 13, 2014
 *      Authors: Avihay Avitan & Stefan Farcas
 */

#include "TimeoutHandler.h"

namespace TimerNameSpace {

/**
 * construct a pass TimeoutHandler
 * mainThread - a pointer to the pass core controller thread
 * trackerThread - - a pointer to the tracking thread
 * interruptedFlag - the flag which will be raised when the interruption occurred
 */
TimeoutHandler::TimeoutHandler(boost::thread * mainThread ,boost::thread * trackerThread, bool * interruptedFlag)
{
	this->mainThread= mainThread;
	this->trackerThread=trackerThread;
	this->interruptedFlag=interruptedFlag;
}

TimeoutHandler::~TimeoutHandler()
{

}

/**
 * handlerFunction - handle the time out of the pass process, printing a timeout message and interrupting the running threads
 */
void TimeoutHandler:: handlerFunction( void )
{
	ProgressStatus status(ProgressStatusType::ERR, "[TimeoutHandler]", "run" , TIME_OUT , true, true);
	Logger::getGSLogger()->logError(status);
	*interruptedFlag = true;
	mainThread->interrupt();
	trackerThread->interrupt();
}

} /* namespace TimerNameSpace */
